package mq.rabbitmq.c_routing;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import mq.rabbitmq.ConnectionUtil;
import mq.rabbitmq.MqConstants;
import mq.rabbitmq.MyDefaultConsumer;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 路由模式：消费者1
 *
 * @author shanzhenbo
 */
public class Consumer1 {

	public static void main(String[] args) throws IOException, TimeoutException {
		Connection connection = ConnectionUtil.getConnection();
		Channel channel = connection.createChannel();
		//声明交换机
		channel.exchangeDeclare(MqConstants.DIRECT_EXCHANGE, BuiltinExchangeType.DIRECT);

		//声明队列
		channel.queueDeclare(MqConstants.DIRECT_QUEUE_INSERT, true, false, false, null);

		//队列绑定交换机
		channel.queueBind(MqConstants.DIRECT_QUEUE_INSERT, MqConstants.DIRECT_EXCHANGE, "insert");

		MyDefaultConsumer consumer = new MyDefaultConsumer(channel, "消费者1");
		channel.basicConsume(MqConstants.DIRECT_QUEUE_INSERT, true, consumer);
	}

}
